// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const result = await db.collection('backgrounds')
      .where({ isActive: true })
      .orderBy('updateTime', 'desc')
      .limit(1)
      .get()
    
    if (result.data && result.data.length > 0) {
      return { success: true, data: result.data[0] }
    } else {
      return { success: true, data: null }
    }
  } catch (error) {
    console.error('获取当前背景失败:', error)
    return { success: false, error: error.message }
  }
} 